import { normalizeContainer } from '../../../../../../../global/element/Func';
import { ObjectOnlyPushSet } from '../../../../../../../global/Func/uniFunc/Func';
import {
  uni_form_attriKey,
  uni_form_uni_comp_default_cla,
} from '../../../DataDefine/sourceData';
import { active_uni_comp_dom_arr_id } from '../comps/focusDisplay_operate_comps/DataDefine/sourceData';

/**
 * 实时 获取 当前 dom 元素 顺序
 * @returns {string[]}
 */
function get_cur_active_comps() {
  let cur_uniComps_node_arr = document.getElementsByClassName(
    uni_form_uni_comp_default_cla
  );

  let ret = [];

  /**
   * @type {HTMLElement}
   */
  let curEl;

  for (curEl of cur_uniComps_node_arr) {
    let key = curEl.getAttribute(uni_form_attriKey);
    if ([undefined, null].includes(key)) {
      continue;
    }
    ObjectOnlyPushSet(ret, key);
  }

  return ret;
}

/**
 * 实时 获取 虚拟 使用 的 comps 的 顺序
 * @returns {string[]}
 */
function get_cur_virtual_comps() {
  let ret = [];

  /**
   * 当前 虚拟 使用 comps 的 节点
   */
  let cur_virtual_comps_arr = normalizeContainer(active_uni_comp_dom_arr_id);

  for (const curEl of cur_virtual_comps_arr.children) {
    let key = curEl.getAttribute(uni_form_attriKey);
    if ([undefined, null].includes(key)) {
      continue;
    }
    ObjectOnlyPushSet(ret, key);
  }

  return ret;
}

export { get_cur_active_comps, get_cur_virtual_comps };
